Week 3 Developer Data product exercise
Melanoma dataset
library(plotly)
library(knitr)
load(file="Melanoma.RData")
kable(Melanoma[1:5,], caption = "Melanoma table content")
Melanoma table content
| 10 |
3 |
1 |
76 |
1972 |
6.76 |
1 |
| 30 |
3 |
1 |
56 |
1968 |
0.65 |
0 |
| 35 |
2 |
1 |
41 |
1977 |
1.34 |
0 |
| 99 |
3 |
0 |
71 |
1968 |
2.90 |
0 |
| 185 |
1 |
1 |
52 |
1965 |
12.08 |
1 |
- time
- Survival time in days since the operation, possibly censored.
- status
- The patients status at the end of the study. 1 indicates that they had died from melanoma, 2 indicates that they were still alive and 3 indicates that they had died from causes unrelated to their melanoma.
- sex
- The patients sex; 1=male, 0=female.
- age
- Age in years at the time of the operation.
- year
- thickness
- ulcer
- Indicator of ulceration; 1=present, 0=absent.
build linear model based on data for plotting
time<-Melanoma$time
status<-Melanoma$status
status<-as.factor(status)
age<-Melanoma$age
thickness<-Melanoma$thickness
ulcer<-Melanoma$ulcer
model<-glm(ulcer~time+thickness,
family = binomial(link = "logit"), data = Melanoma)
Update legend, axis labels and font
f <- list(
family = "Arial, monospace",
size = 18,
color = "#7f7f7f"
)
x <- list(
title = "Time",
titlefont = f
)
y <- list(
title = "Prediction of ulcer based on time and thickness",
titlefont = f
)
Melanoma$sex <- factor(Melanoma$sex,
levels = c(0,1),
labels = c("female", "male"))
Plotting linear predictive model of ulcer as a function of time and tumor thickness
plot_ly(Melanoma, x = ~time, y = ~model, type = "scatter", mode = "lines", color = ~factor(sex)) %>%
layout(xaxis = x, yaxis = y)